package cn.jsu.oj.judgment.net;

import cn.jsu.oj.judgment.net.netHandler.InBoundHandler;
import cn.jsu.oj.judgment.net.netHandler.JudgeClientHandler;
import cn.jsu.oj.judgment.net.netHandler.OutBoundHandler;
import cn.jsu.oj.judgment.satellite.util.SpringUtil;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

public class JudgeChannelInit extends ChannelInitializer<SocketChannel> {

    private final String channelHandlerBean;

    public JudgeChannelInit(String channelHandlerBean) {
        this.channelHandlerBean = channelHandlerBean;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                .addLast(new OutBoundHandler())
                .addLast(new InBoundHandler())
                .addLast((ChannelHandler)SpringUtil.getBean(channelHandlerBean));
    }
}
